/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trunk.view.tool;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.JToolBar;
import trunk.model.Dessin;
import trunk.model.EDrawTool;

/**
 * Class ToolPaletteView
 * 
 * Partie graphique de la palette d'outils
 * 
 * @author LEFEVRE Michael
 * @author THOUE Jonathan
 */
public class ToolPaletteView extends JToolBar{
        
    private List<ToolButton> toolButton = new ArrayList<ToolButton>();
    
    private JLabel currentTool;
    /**
     * Constructeur du composant
     */
    public ToolPaletteView() {
      setPreferredSize(new Dimension(85, 150));
      setLayout(new FlowLayout(FlowLayout.LEFT));
      List<EDrawTool> listTool = Arrays.asList(
              EDrawTool.CIRCLE,
              EDrawTool.POINT,
              EDrawTool.POLYGON,
              EDrawTool.RECTANGLE,
              EDrawTool.SEGMENT,
              EDrawTool.SELECT,
              EDrawTool.AXE);
      ToolButton button;
      for (EDrawTool tool : listTool) {
           button = new ToolButton(tool);
           toolButton.add(button);
           add(button);
      }
      currentTool = new JLabel();       
      currentTool.setPreferredSize(new Dimension(50, 20));
      currentTool.setText(".");
      currentTool.setToolTipText("Votre outils actuelle.");
      add(currentTool);
    }
    /**
     *Methode pour abonner les boutons au listenner
     * @param ctrl - listenner du composant
     */ 
    public void setToolPaletteCtrl(ToolPaletteCtrl ctrl){
        for (ToolButton button : toolButton) {
            button.addActionListener(ctrl);
        }
    }
    /**
     * Méthode de mise à jour de la vue
     * @param dessin - dessin courrant
     */
    public void update(Dessin dessin) {
        setCurrentTool(dessin.getCurrentTool());
    }
    /**
     * Set currentTool
     * @param tool - change l'outil courrant
     */
    public void setCurrentTool(EDrawTool tool){
       if(tool ==EDrawTool.POINT){
            currentTool.setText(".");
            currentTool.setToolTipText("Draw a pixel.");
        }else if(tool ==EDrawTool.SEGMENT){
            currentTool.setText("/");
            currentTool.setToolTipText("Draw a segment.");
        }else if(tool ==EDrawTool.POLYGON){
            currentTool.setText("\u0394");
            currentTool.setToolTipText("Draw a polygon.");
        }else if(tool ==EDrawTool.CIRCLE){
            currentTool.setText("\u039F");
            currentTool.setToolTipText("Draw a circle.");
        }else if(tool ==EDrawTool.RECTANGLE){
            currentTool.setText("\u25FB");
            currentTool.setToolTipText("Draw a rectangle.");
        }else if(tool ==EDrawTool.SELECT){
            currentTool.setText("S");
            currentTool.setToolTipText("Selection Mode");
        }else if(tool ==EDrawTool.AXE){
            currentTool.setText("+");
            currentTool.setToolTipText("Change Axe/Origine");
        }
       
    }
    
}
